//#define  _GNU_SOURCE
#include<stdio.h>
#include<stdlib.h>
#include<dirent.h>
#include<unistd.h>

#define PAT "/etc"
int main(int argc,char **argv)
{
	DIR *dp;
	struct dirent *dirt;
	long size;
    char *buf;
    char* cwd;
	char *path;
	size=pathconf(".",_PC_PATH_MAX);
//　　　　if((buf=(char *)malloc((size_t)size))!=NULL)
        //path=get_current_dir_name();
		if(argc<2)
		{
				buf=(char *)malloc((size_t)size);
				if(buf!=NULL)
				{
					path=getcwd(buf,(size_t)size);
              		dp=opendir(path);
					free(buf);
				}
				else
					return -1;
//					path=getcwd(buf,(size_t)size);
			//path=get_current_dir_name();
//			dp=opendir(path);
		}
		else
			dp=opendir(argv[1]);
		if(dp==NULL)
		{
				perror("opendir error");
				return -1;
		}
		while((dirt=readdir(dp))!=NULL)
		{
			puts(dirt->d_name);
		}
		closedir(dp);

		return 0;
}
